package com.yzt.message;

import android.app.Application;
import android.content.res.Resources;
import android.os.Handler;
import android.os.Looper;

import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MediatorLiveData;
import androidx.lifecycle.MutableLiveData;

import com.yzt.p_base.AppUtils;

import io.rong.common.RLog;
import io.rong.imkit.ConversationEventListener;
import io.rong.imkit.IMCenter;
import io.rong.imkit.R.drawable;
import io.rong.imkit.R.string;
import io.rong.imkit.config.DataProcessor;
import io.rong.imkit.config.RongConfigCenter;
import io.rong.imkit.conversationlist.model.BaseUiConversation;
import io.rong.imkit.conversationlist.model.GatheredConversation;
import io.rong.imkit.conversationlist.model.GroupConversation;
import io.rong.imkit.conversationlist.model.PublicServiceConversation;
import io.rong.imkit.conversationlist.model.SingleConversation;
import io.rong.imkit.event.Event.RefreshEvent;
import io.rong.imkit.event.actionevent.ClearEvent;
import io.rong.imkit.event.actionevent.DeleteEvent;
import io.rong.imkit.event.actionevent.DownloadEvent;
import io.rong.imkit.event.actionevent.InsertEvent;
import io.rong.imkit.event.actionevent.MessageEventListener;
import io.rong.imkit.event.actionevent.RecallEvent;
import io.rong.imkit.event.actionevent.SendEvent;
import io.rong.imkit.event.actionevent.SendMediaEvent;
import io.rong.imkit.feature.resend.ResendManager;
import io.rong.imkit.model.NoticeContent;
import io.rong.imkit.notification.RongNotificationManager;
import io.rong.imkit.widget.refresh.constant.RefreshState;
import io.rong.imlib.RongIMClient;
import io.rong.imlib.RongIMClient.ConnectionStatusListener;
import io.rong.imlib.RongIMClient.ConversationStatusListener;
import io.rong.imlib.RongIMClient.ErrorCode;
import io.rong.imlib.RongIMClient.OnRecallMessageListener;
import io.rong.imlib.RongIMClient.OnReceiveMessageWrapperListener;
import io.rong.imlib.RongIMClient.ReadReceiptListener;
import io.rong.imlib.RongIMClient.ResultCallback;
import io.rong.imlib.RongIMClient.SyncConversationReadStatusListener;
import io.rong.imlib.RongIMClient.ConnectionStatusListener.ConnectionStatus;
import io.rong.imlib.model.Conversation;
import io.rong.imlib.model.ConversationStatus;
import io.rong.imlib.model.Message;
import io.rong.imlib.model.Conversation.ConversationType;
import io.rong.imlib.model.Message.SentStatus;
import io.rong.message.ReadReceiptMessage;
import io.rong.message.RecallNotificationMessage;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CopyOnWriteArrayList;

public class CustomConversationListViewModel extends AndroidViewModel {

    private final String TAG = CustomConversationListViewModel.class.getSimpleName();
    protected ConversationType[] mSupportedTypes;
    protected int mSizePerPage;
    protected long mLastSyncTime;
    protected Application mApplication;
    protected CopyOnWriteArrayList<BaseUiConversation> mUiConversationList = new CopyOnWriteArrayList();
    protected MediatorLiveData<List<BaseUiConversation>> mConversationListLiveData;
    protected DataProcessor<Conversation> mDataFilter;
    protected Handler mHandler;
    private final MutableLiveData<ConnectionStatus> mConnectionStatusLiveData = new MutableLiveData();
    private final MutableLiveData<NoticeContent> mNoticeContentLiveData = new MutableLiveData();
    private final MutableLiveData<RefreshEvent> mRefreshEventLiveData = new MutableLiveData();
    private boolean isTaskScheduled;

    private final ConversationEventListener mConversationEventListener = new ConversationEventListener() {
        @Override
        public void onSaveDraft(ConversationType type, String targetId, String content) {
            CustomConversationListViewModel.this.getConversation(type, targetId);
        }

        @Override
        public void onClearedMessage(ConversationType type, String targetId) {
            CustomConversationListViewModel.this.getConversation(type, targetId);
        }

        @Override
        public void onClearedUnreadStatus(ConversationType type, String targetId) {
            CustomConversationListViewModel.this.getConversation(type, targetId);
        }

        @Override
        public void onConversationRemoved(ConversationType type, String targetId) {
            BaseUiConversation oldItem = CustomConversationListViewModel.this.findConversationFromList(type, targetId, CustomConversationListViewModel.this.mDataFilter.isGathered(type));
            if (oldItem != null) {
                CustomConversationListViewModel.this.mUiConversationList.remove(oldItem);
                CustomConversationListViewModel.this.mConversationListLiveData.postValue(CustomConversationListViewModel.this.mUiConversationList);
            }
        }

        @Override
        public void onOperationFailed(ErrorCode code) {
        }

        @Override
        public void onClearConversations(ConversationType... conversationTypes) {
            RLog.d(CustomConversationListViewModel.this.TAG, "onClearConversations");
            List<ConversationType> clearedTypes = Arrays.asList(conversationTypes);

            for (BaseUiConversation item : CustomConversationListViewModel.this.mUiConversationList) {
                if (clearedTypes.contains(item.mCore.getConversationType())) {
                    CustomConversationListViewModel.this.mUiConversationList.remove(item);
                }
            }

            CustomConversationListViewModel.this.mConversationListLiveData.postValue(CustomConversationListViewModel.this.mUiConversationList);
        }
    };

    private final MessageEventListener mMessageEventListener = new MessageEventListener() {

        @Override
        public void onSendMessage(SendEvent event) {
            if (event != null && event.getMessage() != null) {
                CustomConversationListViewModel.this.getConversation(event.getMessage().getConversationType(), event.getMessage().getTargetId());
            }
        }

        @Override
        public void onSendMediaMessage(SendMediaEvent event) {
            if (event != null && event.getEvent() != 2 && event.getMessage() != null) {
                CustomConversationListViewModel.this.getConversation(event.getMessage().getConversationType(), event.getMessage().getTargetId());
            }
        }

        @Override
        public void onDownloadMessage(DownloadEvent event) {
            if (event != null) {
                ConversationType type = event.getMessage().getConversationType();
                String targetId = event.getMessage().getTargetId();
                BaseUiConversation oldItem = CustomConversationListViewModel.this.findConversationFromList(type, targetId, CustomConversationListViewModel.this.mDataFilter.isGathered(type));
                if (oldItem != null && oldItem.mCore.getLatestMessageId() == event.getMessage().getMessageId() && event.getEvent() != 1) {
                    CustomConversationListViewModel.this.getConversation(type, targetId);
                }
            }
        }

        @Override
        public void onDeleteMessage(DeleteEvent event) {
            if (event != null) {
                CustomConversationListViewModel.this.getConversation(event.getConversationType(), event.getTargetId());
            }
        }

        @Override
        public void onRecallEvent(RecallEvent event) {
            if (event != null) {
                CustomConversationListViewModel.this.getConversation(event.getConversationType(), event.getTargetId());
            }
        }

        @Override
        public void onRefreshEvent(io.rong.imkit.event.actionevent.RefreshEvent event) {
        }

        @Override
        public void onInsertMessage(InsertEvent event) {
            if (event != null) {
                ConversationType type = event.getMessage().getConversationType();
                String targetId = event.getMessage().getTargetId();
                CustomConversationListViewModel.this.getConversation(type, targetId);
            }
        }

        @Override
        public void onClearMessages(ClearEvent event) {
            CustomConversationListViewModel.this.getConversation(event.getConversationType(), event.getTargetId());
        }
    };

    private final OnReceiveMessageWrapperListener mOnReceiveMessageListener = new OnReceiveMessageWrapperListener() {
        @Override
        public boolean onReceived(Message message, int left, boolean hasPackage, boolean offline) {
            if (message == null) {
                return false;
            }

            if (message.getConversationType() == ConversationType.PRIVATE) {
                CustomConversationListViewModel.this.getConversationList(false);
            }
            if (message.getConversationType() == ConversationType.GROUP) {
                CustomConversationListViewModel.this.getConversationList(false);
            }
            return false;
        }
    };

    private final ReadReceiptListener mReadReceiptListener = new ReadReceiptListener() {

        @Override
        public void onReadReceiptReceived(Message message) {
            if (message != null && message.getContent() instanceof ReadReceiptMessage) {
                ConversationType type = message.getConversationType();
                BaseUiConversation oldItem = CustomConversationListViewModel.this.findConversationFromList(type, message.getTargetId(), CustomConversationListViewModel.this.mDataFilter.isGathered(type));
                if (oldItem != null
                        && (type.equals(ConversationType.PRIVATE) || type.equals(ConversationType.GROUP))
                        && oldItem.mCore.getSentTime() == ((ReadReceiptMessage) message.getContent()).getLastMessageSendTime()) {
                    oldItem.mCore.setSentStatus(SentStatus.READ);
                    CustomConversationListViewModel.this.mConversationListLiveData.postValue(CustomConversationListViewModel.this.mUiConversationList);
                }
            }

        }

        @Override
        public void onMessageReceiptRequest(ConversationType type, String targetId, String messageUId) {
        }

        @Override
        public void onMessageReceiptResponse(ConversationType type, String targetId, String messageUId, HashMap<String, Long> respondUserIdList) {
        }
    };

    private final OnRecallMessageListener mOnRecallMessageListener = new OnRecallMessageListener() {

        @Override
        public boolean onMessageRecalled(Message message, RecallNotificationMessage recallNotificationMessage) {
            if (message != null) {
                CustomConversationListViewModel.this.getConversation(message.getConversationType(), message.getTargetId());
            }
            return false;
        }
    };

    private final SyncConversationReadStatusListener mSyncConversationReadStatusListener = new SyncConversationReadStatusListener() {

        @Override
        public void onSyncConversationReadStatus(ConversationType type, String targetId) {
            BaseUiConversation oldItem = CustomConversationListViewModel.this.findConversationFromList(type, targetId, CustomConversationListViewModel.this.mDataFilter.isGathered(type));
            if (oldItem != null) {
                oldItem.mCore.setUnreadMessageCount(0);
                CustomConversationListViewModel.this.mConversationListLiveData.postValue(CustomConversationListViewModel.this.mUiConversationList);
            }
        }
    };

    private final ConnectionStatusListener mConnectionStatusListener = new ConnectionStatusListener() {
        @Override
        public void onChanged(ConnectionStatus status) {
            CustomConversationListViewModel.this.mConnectionStatusLiveData.postValue(status);
            if (status.equals(ConnectionStatus.CONNECTED)) {
                CustomConversationListViewModel.this.getConversationList(false);
            }
            CustomConversationListViewModel.this.updateNoticeContent(status);
        }
    };
    private final ConversationStatusListener mConversationStatusListener = new ConversationStatusListener() {

        @Override
        public void onStatusChanged(ConversationStatus[] conversationStatus) {
            CustomConversationListViewModel.this.onConversationStatusChange(conversationStatus);
        }
    };

    public CustomConversationListViewModel(Application application) {
        super(application);
        this.mApplication = application;
        this.mHandler = new Handler(Looper.getMainLooper());
        this.mSupportedTypes = RongConfigCenter.conversationListConfig().getDataProcessor().supportedTypes();
        this.mSizePerPage = RongConfigCenter.conversationListConfig().getConversationCountPerPage();
        this.mDataFilter = RongConfigCenter.conversationListConfig().getDataProcessor();
        this.mConversationListLiveData = new MediatorLiveData();

        IMCenter.getInstance().
                addOnReceiveMessageListener(this.mOnReceiveMessageListener);

        IMCenter.getInstance().
                addConnectionStatusListener(this.mConnectionStatusListener);

        IMCenter.getInstance().
                addConversationStatusListener(this.mConversationStatusListener);

        IMCenter.getInstance().
                addReadReceiptListener(this.mReadReceiptListener);

        IMCenter.getInstance().
                addSyncConversationReadStatusListener(this.mSyncConversationReadStatusListener);

        IMCenter.getInstance().
                addOnRecallMessageListener(this.mOnRecallMessageListener);

        IMCenter.getInstance().
                addConversationEventListener(this.mConversationEventListener);

        IMCenter.getInstance().
                addMessageEventListener(this.mMessageEventListener);
    }

    public void getConversationList(final boolean loadMore) {
        if (!this.isTaskScheduled) {
            this.isTaskScheduled = true;
            this.mHandler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    long timestamp = 0L;
                    CustomConversationListViewModel.this.isTaskScheduled = false;
                    if (loadMore) {
                        timestamp = CustomConversationListViewModel.this.mLastSyncTime;
                    }

                    RongIMClient.getInstance().getConversationListByPage(new ResultCallback<List<Conversation>>() {

                        @Override
                        public void onSuccess(List<Conversation> conversations) {
                            if (loadMore) {
                                CustomConversationListViewModel.this.mRefreshEventLiveData.postValue(new RefreshEvent(RefreshState.LoadFinish));
                            } else {
                                CustomConversationListViewModel.this.mRefreshEventLiveData.postValue(new RefreshEvent(RefreshState.RefreshFinish));
                            }

                            if (conversations != null && conversations.size() != 0) {
                                RLog.d(CustomConversationListViewModel.this.TAG, "getConversationListByPage. size:" + conversations.size());
                                CustomConversationListViewModel.this.mLastSyncTime = conversations.get(conversations.size() - 1).getSentTime();
                                CopyOnWriteArrayList<Conversation> copyList = new CopyOnWriteArrayList(conversations);
                                List<Conversation> filterResult = CustomConversationListViewModel.this.mDataFilter.filtered(copyList);
                                if (filterResult != null && filterResult.size() > 0) {
                                    Iterator var4 = filterResult.iterator();

                                    while (true) {
                                        while (var4.hasNext()) {
                                            Conversation conversation = (Conversation) var4.next();
                                            boolean isGathered = CustomConversationListViewModel.this.mDataFilter.isGathered(conversation.getConversationType());
                                            BaseUiConversation oldItem = CustomConversationListViewModel.this.findConversationFromList(conversation.getConversationType(), conversation.getTargetId(), isGathered);
                                            if (oldItem != null) {
                                                oldItem.onConversationUpdate(conversation);
                                            } else if (isGathered) {
                                                CustomConversationListViewModel.this.mUiConversationList.add(new GatheredConversation(CustomConversationListViewModel.this.mApplication.getApplicationContext(), conversation));
                                            } else if (conversation.getConversationType().equals(ConversationType.GROUP)) {
                                                CustomConversationListViewModel.this.mUiConversationList.add(new GroupConversation(CustomConversationListViewModel.this.mApplication.getApplicationContext(), conversation));
                                            } else if (!conversation.getConversationType().equals(ConversationType.PUBLIC_SERVICE) && !conversation.getConversationType().equals(ConversationType.APP_PUBLIC_SERVICE)) {
                                                CustomConversationListViewModel.this.mUiConversationList.add(new SingleConversation(CustomConversationListViewModel.this.mApplication.getApplicationContext(), conversation));
                                            } else {
                                                CustomConversationListViewModel.this.mUiConversationList.add(new PublicServiceConversation(CustomConversationListViewModel.this.mApplication.getApplicationContext(), conversation));
                                            }
                                        }
                                        CustomConversationListViewModel.this.sort();
                                        CustomConversationListViewModel.this.mConversationListLiveData.postValue(CustomConversationListViewModel.this.mUiConversationList);
                                        break;
                                    }
                                }
                            }
                        }

                        @Override
                        public void onError(ErrorCode e) {
                            if (loadMore) {
                                CustomConversationListViewModel.this.mRefreshEventLiveData.postValue(new RefreshEvent(RefreshState.LoadFinish));
                            } else {
                                CustomConversationListViewModel.this.mRefreshEventLiveData.postValue(new RefreshEvent(RefreshState.RefreshFinish));
                            }

                        }
                    }, timestamp, CustomConversationListViewModel.this.mSizePerPage, CustomConversationListViewModel.this.mSupportedTypes);
                }
            }, 500L);
        }
    }

    protected boolean isSupported(ConversationType type) {
        if (this.mSupportedTypes != null) {
            ConversationType[] var2 = this.mSupportedTypes;
            int var3 = var2.length;

            for (int var4 = 0; var4 < var3; ++var4) {
                ConversationType conversationType = var2[var4];
                if (conversationType.equals(type)) {
                    return true;
                }
            }
        }
        return false;
    }

    private void getConversation(ConversationType type, String targetId) {
        RongIMClient.getInstance().getConversation(type, targetId, new ResultCallback<Conversation>() {

            @Override
            public void onSuccess(Conversation conversation) {
                if (conversation != null) {
                    if (Objects.equals(conversation.getSentStatus(), SentStatus.FAILED) && ResendManager.getInstance().needResend(conversation.getLatestMessageId())) {
                        conversation.setSentStatus(SentStatus.SENDING);
                    }

                    CustomConversationListViewModel.this.updateByConversation(conversation);
                }
            }

            @Override
            public void onError(ErrorCode errorCode) {
            }
        });
    }

    protected void updateByConversation(Conversation conversation) {
        if (conversation != null) {
            List<Conversation> list = new CopyOnWriteArrayList();
            list.add(conversation);
            List<Conversation> filterList = this.mDataFilter.filtered(list);
            if (filterList != null && filterList.size() > 0 && this.isSupported(conversation.getConversationType())) {
                BaseUiConversation oldItem = this.findConversationFromList(conversation.getConversationType(), conversation.getTargetId(), this.mDataFilter.isGathered(conversation.getConversationType()));
                if (oldItem != null) {
                    oldItem.onConversationUpdate(conversation);
                } else if (this.mDataFilter.isGathered(conversation.getConversationType())) {
                    this.mUiConversationList.add(new GatheredConversation(this.mApplication.getApplicationContext(), conversation));
                } else if (conversation.getConversationType().equals(ConversationType.GROUP)) {
                    this.mUiConversationList.add(new GroupConversation(this.mApplication.getApplicationContext(), conversation));
                } else if (!conversation.getConversationType().equals(ConversationType.PUBLIC_SERVICE) && !conversation.getConversationType().equals(ConversationType.APP_PUBLIC_SERVICE)) {
                    this.mUiConversationList.add(new SingleConversation(this.mApplication.getApplicationContext(), conversation));
                } else {
                    this.mUiConversationList.add(new PublicServiceConversation(this.mApplication.getApplicationContext(), conversation));
                }

                this.sort();
                this.mConversationListLiveData.postValue(this.mUiConversationList);
            }
        }
    }

    private void onConversationStatusChange(ConversationStatus[] statuses) {
        ConversationStatus[] var2 = statuses;
        int var3 = statuses.length;

        for (int var4 = 0; var4 < var3; ++var4) {
            ConversationStatus status = var2[var4];
            ConversationType type = status.getConversationType();
            BaseUiConversation oldItem = this.findConversationFromList(type, status.getTargetId(), this.mDataFilter.isGathered(type));
            if (oldItem != null) {
                if (status.getStatus().get("2") != null) {
                    oldItem.mCore.setTop(status.isTop());
                }

                if (status.getStatus().get("1") != null) {
                    oldItem.mCore.setNotificationStatus(status.getNotifyStatus());
                }

                this.sort();
                this.mConversationListLiveData.postValue(this.mUiConversationList);
            } else {
                this.getConversation(type, status.getTargetId());
            }
        }
    }

    @Override
    protected void onCleared() {
        IMCenter.getInstance().removeConnectionStatusListener(this.mConnectionStatusListener);
        IMCenter.getInstance().removeOnReceiveMessageListener(this.mOnReceiveMessageListener);
        IMCenter.getInstance().removeConversationStatusListener(this.mConversationStatusListener);
        IMCenter.getInstance().removeMessageEventListener(this.mMessageEventListener);
        IMCenter.getInstance().removeReadReceiptListener(this.mReadReceiptListener);
        IMCenter.getInstance().removeOnRecallMessageListener(this.mOnRecallMessageListener);
        IMCenter.getInstance().removeConversationEventListener(this.mConversationEventListener);
        IMCenter.getInstance().removeSyncConversationReadStatusListeners(this.mSyncConversationReadStatusListener);
    }

    /**
     * 根据时间排序
     */
    protected void sort() {
//        List temp = Arrays.asList(this.mUiConversationList.toArray());
//        Collections.sort(temp, new Comparator<BaseUiConversation>() {
//            @Override
//            public int compare(BaseUiConversation o1, BaseUiConversation o2) {
//                if ((!o1.mCore.isTop() || !o2.mCore.isTop()) && (o1.mCore.isTop() || o2.mCore.isTop())) {
//                    if (o1.mCore.isTop() && !o2.mCore.isTop()) {
//                        return -1;
//                    } else {
//                        return !o1.mCore.isTop() && o2.mCore.isTop() ? 1 : 0;
//                    }
//                } else if (MessageConstants.TYPE_NOMI_SERVICE.equals(o1.mCore.getTargetId())) {
//                    return 1;
//                } else if (o1.mCore.getSentTime() > o2.mCore.getSentTime()) {
//                    return -1;
//                } else {
//                    return o1.mCore.getSentTime() < o2.mCore.getSentTime() ? 1 : 0;
//                }
//            }
//        });
//        this.mUiConversationList.clear();
//        this.mUiConversationList.addAll(temp);
        BaseUiConversation nomiTeam = null;
        BaseUiConversation nomiService = null;

        ArrayList<BaseUiConversation> listData = new ArrayList<>();

        for (BaseUiConversation bean : this.mUiConversationList) {

            if (bean.mCore.getConversationTitle().equals(AppUtils.getApp().getString(R.string.office_notice))) {
                nomiTeam = bean;
            } else if (bean.mCore.getTargetId().equals(MessageConstants.TYPE_NOMI_SERVICE)) {
                nomiService = bean;
            } else {
                listData.add(bean);
            }
        }

        List temp = Arrays.asList(listData.toArray());

        Collections.sort(temp, new Comparator<BaseUiConversation>() {

            @Override
            public int compare(BaseUiConversation o1, BaseUiConversation o2) {
                if ((!o1.mCore.isTop() || !o2.mCore.isTop()) && (o1.mCore.isTop() || o2.mCore.isTop())) {
                    if (o1.mCore.isTop() && !o2.mCore.isTop()) {
                        return -1;
                    } else {
                        return !o1.mCore.isTop() && o2.mCore.isTop() ? 1 : 0;
                    }
                } else if (MessageConstants.TYPE_NOMI_SERVICE.equals(o1.mCore.getTargetId()) && "2".equals(o2.mCore.getTargetId())) {
                    return 1;
                } else if (MessageConstants.TYPE_NOMI_SERVICE.equals(o1.mCore.getTargetId())) {
                    return 1;
                } else if (o1.mCore.getSentTime() > o2.mCore.getSentTime()) {
                    return -1;
                } else {
                    return o1.mCore.getSentTime() < o2.mCore.getSentTime() ? 1 : 0;
                }
            }
        });
        this.mUiConversationList.clear();
        this.mUiConversationList.addAll(temp);
        if (nomiService != null) {
            this.mUiConversationList.add(0, nomiService);
        }
        if (nomiTeam != null) {
            this.mUiConversationList.add(0, nomiTeam);
        }
    }

    protected BaseUiConversation findConversationFromList(ConversationType conversationType, String targetId, boolean isGathered) {

        Iterator var4 = this.mUiConversationList.iterator();

        BaseUiConversation uiConversation;
        do {
            if (!var4.hasNext()) {
                return null;
            }

            uiConversation = (BaseUiConversation) var4.next();
            if (isGathered && uiConversation instanceof GatheredConversation && uiConversation.mCore.getConversationType().equals(conversationType)) {
                return uiConversation;
            }
        } while (isGathered || !uiConversation.mCore.getConversationType().equals(conversationType) || !uiConversation.mCore.getTargetId().equals(targetId));

        return uiConversation;
    }

    public MediatorLiveData<List<BaseUiConversation>> getConversationListLiveData() {
        return this.mConversationListLiveData;
    }

    public LiveData<NoticeContent> getNoticeContentLiveData() {
        return this.mNoticeContentLiveData;
    }

    public LiveData<RefreshEvent> getRefreshEventLiveData() {
        return this.mRefreshEventLiveData;
    }

    private void updateNoticeContent(ConnectionStatus status) {
        NoticeContent noticeContent = new NoticeContent();
        String content = null;
        boolean isShowContent = true;
        int resId = 0;
        Resources resources = this.mApplication.getResources();
        if (!RongConfigCenter.conversationListConfig().isEnableConnectStateNotice()) {
            RLog.e(this.TAG, "rc_is_show_warning_notification is disabled.");
        } else {
            if (status.equals(ConnectionStatus.NETWORK_UNAVAILABLE)) {
                content = resources.getString(string.rc_conversation_list_notice_network_unavailable);
                resId = drawable.rc_ic_error_notice;
            } else if (status.equals(ConnectionStatus.KICKED_OFFLINE_BY_OTHER_CLIENT)) {
                content = resources.getString(string.rc_conversation_list_notice_kicked);
                resId = drawable.rc_ic_error_notice;
            } else if (status.equals(ConnectionStatus.CONNECTED)) {
                isShowContent = false;
            } else if (status.equals(ConnectionStatus.UNCONNECTED)) {
                content = resources.getString(string.rc_conversation_list_notice_disconnect);
                resId = drawable.rc_ic_error_notice;
            } else if (status.equals(ConnectionStatus.CONNECTING) || status.equals(ConnectionStatus.SUSPEND)) {
                content = resources.getString(string.rc_conversation_list_notice_connecting);
                resId = drawable.rc_conversationlist_notice_connecting_animated;
            }

            noticeContent.setContent(content);
            noticeContent.setShowNotice(isShowContent);
            noticeContent.setIconResId(resId);
            this.mNoticeContentLiveData.postValue(noticeContent);
        }
    }

    public void clearAllNotification() {
        if (RongConfigCenter.featureConfig().rc_wipe_out_notification_message) {
            RongNotificationManager.getInstance().clearAllNotification();
        }
    }
}
